import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () => import('@/views/login/auth-redirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/error-page/401'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: '/goods/list',
        noShow: true,
        // children: [
        //     {
        //         path: 'dashboard',
        //         component: () => import('@/views/dashboard/index'),
        //         name: 'Dashboard',
        //         meta: { title: '首页', icon: 'dashboard', affix: true,noShow: true, }
        //     }
        // ]
    },
    {
        path: '/member',
        component: Layout,
        redirect: '/member/list',
        alwaysShow: true,
        name: 'Member',
        meta: {
            title: '会员管理',
            icon: 'member'
        },
        children: [
            {
                path: 'list',
                component: () => import('@/views/member/index.vue'),
                name: 'memberList',
                meta: { title: '注册会员管理', noCache: true,keepAliveFlag: true}
            },
            {
                path: 'detail',
                component: () => import('@/views/member/detail.vue'),
                name: 'MemberDetail',
                meta: { title: '会员详情', noCache: true,noShow:true }
            },
        ]
    },
    {
        path: '/goods',
        component: Layout,
        redirect: '/goods/list',
        alwaysShow: true,
        name: 'Goods',
        meta: {
            title: '商品管理',
            icon: 'goods'
        },
        children: [
            {
                path: 'category',
                component: () => import('@/views/goods/category'),
                name: 'GoodsCategory',
                meta: {
                    title: '商品分类管理',
                    noCache: true,
                    keepAliveFlag: true
                }
            },
            {
                path: 'list',
                component: () => import('@/views/goods/index'),
                name: 'GoodsList',
                meta: {
                    title: '自营商品发布',
                    keepAliveFlag: true,
                }
            },
            {
                path: 'add',
                component: () => import('@/views/goods/add'),
                name: 'GoodsAdd',
                meta: {
                    title: '商品发布',
                },
                hidden: true
            },
            {
                path: 'look/:id',
                component: () => import('@/views/goods/look'),
                name: 'GoodsDetail',
                meta: {
                    title: '商品详情',
                },
                hidden: true
            },
            {
                path: 'order',
                component: () => import('@/views/goods/order'),
                name: 'GoodsOrder',
                meta: {
                    title: '商品订单管理',
                    keepAliveFlag: true
                }
            },
            {
                path: 'order/:id',
                component: () => import('@/views/goods/order/detail'),
                name: 'OrderDetail',
                meta: {
                    title: '订单详情',
                    //keepAliveFlag: true,
                },
                hidden: true
            }
        ]
    },
    {
        path: '/artist',
        component: Layout,
        redirect: '/artist/list',
        alwaysShow: true,
        name: 'Artist',
        meta: {
            title: '艺术家管理',
            icon: 'artist'
        },
        children: [
            {
                path: 'list',
                component: () => import('@/views/artist/index.vue'),
                name: 'ArtistList',
                meta: { title: '认证艺术家管理', noCache: true,keepAliveFlag: true }
            },
            {
                path: 'add',
                component: () => import('@/views/artist/add.vue'),
                name: 'ArtistAdd',
                meta: { title: '创建艺术家', noCache: true,noShow:true }
            },
        ]
    },
    {
        path: '/arlandmark',
        component: Layout,
        redirect: '/arlandmark/list',
        alwaysShow: true,
        name: 'Arlandmark',
        meta: {
            title: 'AR地标管理',
            icon: 'arlandmark'
        },
        children: [
            {
                path: 'list',
                component: () => import('@/views/arLandmark/index.vue'),
                name: 'ArlandmarkList',
                meta: { title: 'AR地标管理', noCache: true,keepAliveFlag: true }
            },
            {
                path: 'add',
                component: () => import('@/views/arLandmark/add.vue'),
                name: 'ArlandmarkAdd',
                meta: { title: '创建AR地标', noCache: true,noShow:true }
            },
            {
                path: 'look/:id',
                component: () => import('@/views/arLandmark/look.vue'),
                name: 'ArlandmarkLook',
                meta: { title: 'AR地标详情', noCache: true,noShow:true }
            },
        ]
    },
    {
        path: '/armeet',
        component: Layout,
        redirect: '/armeet/list',
        alwaysShow: true,
        name: 'ArMeet',
        meta: {
            title: 'AR遇见艺术专题',
            icon: 'meet'
        },
        children: [
            {
                path: 'list',
                component: () => import('@/views/arMeet/index.vue'),
                name: 'ArMeetList',
                meta: { title: 'AR遇见艺术专题', noCache: true,keepAliveFlag: true }
            },
            {
                path: 'add',
                component: () => import('@/views/arMeet/add.vue'),
                name: 'ArMeetAdd',
                meta: { title: '创建AR艺术遇见', noCache: true,noShow:true }
            },
        ]
    },
    {
        path: '/redpacket',
        component: Layout,
        redirect: '/redpacket/list',
        alwaysShow: true,
        name: 'RedPacket',
        meta: {
            title: '红包管理',
            icon: 'redpacket'
        },
        children: [
            {
                path: 'list',
                component: () => import('@/views/redPacket/index.vue'),
                name: 'RedPacketList',
                meta: { title: '红包发放', keepAliveFlag: true}
            }
        ]
    },
    {
        path: '/settle',
        component: Layout,
        redirect: '/settle/list',
        alwaysShow: true,
        name: 'Settle',
        meta: {
            title: '财务结算管理',
            icon: 'settle'
        },
        children: [
            {
                path: 'list',
                component: () => import('@/views/settle/index.vue'),
                name: 'SettleList',
                meta: { title: '财务收入管理', keepAliveFlag: true}
            },
            {
                path: 'detail',
                component: () => import('@/views/settle/details.vue'),
                name: 'SettleDetails',
                meta: { title: '收入明细',noShow:true}
            }
        ]
    },
]


/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
    { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
